package com.byxy.ssm.demo.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.byxy.ssm.demo.dao.ForumDao;
import com.byxy.ssm.demo.dao.TabDao;
import com.byxy.ssm.demo.dao.TipDao;
import com.byxy.ssm.demo.dao.UserDao;
import com.byxy.ssm.demo.entity.Forum;
import com.byxy.ssm.demo.entity.Tab;
import com.byxy.ssm.demo.entity.Tip;
import com.byxy.ssm.demo.entity.User;
import com.byxy.ssm.demo.service.TipService;
import com.byxy.ssm.demo.vo.TipVO;
import com.fasterxml.jackson.databind.util.BeanUtil;
@Service
@Transactional
public class TipServiceImpl implements TipService {
	@Autowired
	private TipDao tipDao;
	@Autowired
	private UserDao userDao;
	@Autowired
	private TabDao tabDao;
	@Autowired
	private ForumDao forumDao;
	@Override
	public void add(Tip tip) {
		// TODO Auto-generated method stub
		tipDao.add(tip);
	}
	@Override
	public TipVO findById(Integer tipId) {
		Tip tip = tipDao.finById(tipId);
		TipVO tipVO = new TipVO();
		BeanUtils.copyProperties(tip, tipVO);
		User u = userDao.getById(tip.getUserId());
		
		if (u.getUserNick()!= null && u.getUserNick().equals("")) 
			tipVO.setUserName(u.getUserNick());
		else {
			tipVO.setUserName(u.getUserName());
			}
			Tab tab = tabDao.getById(tip.getTabId());
			tipVO.setTabName(tab.getTabName());
			Forum forum =forumDao.getById(tab.getForumId());
			tipVO.setForumName(forum.getForumName());
		return tipVO;
	}

}
